package com.liu.oa.employee.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.liu.oa.employee.entity.EmployeeEntity;
import com.liu.oa.employee.service.EmployeeService;

@Controller
@RequestMapping("/employee")
public class EmployeeController {
	
	@Autowired
	private EmployeeService service;
	
	
	/*//http:localhost:8090/base-mapper/employee/insert.do?username=lh&deparment_id=1001
	@RequestMapping("/insert")
	@ResponseBody
	public int myInsert(EmployeeEntity entity) {
		int i=0;
		try {
			i = service.insert(entity);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return i;
	}*/
	
	
	//http:localhost:8090/base-mapper/employee/insert/a.do?username=lh&deparment_id=1001
	@RequestMapping(value="/insert/**/a",method=RequestMethod.GET)
	@ResponseBody
	public int myInsert2(EmployeeEntity entity) {
		int i=0;
		try {
			i = service.insert(entity);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return i;
	}
	
	
	//http://localhost:8090/base-mapper/employee/insert/username/1001.do
	@RequestMapping("/insert/*/{username}/{deparmentId}")
	@ResponseBody
	public int myInsert(@PathVariable(value="username") String username22,
						@PathVariable(value="deparmentId") String deparmentId) {
		int i=0;
		try {
//			i = service.insert(entity);
			System.out.println(username22+","+deparmentId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return i;
	}
	
	//http://localhost:8090/base-mapper/employee/myfindAll.do
	@RequestMapping("/myfindAll")
	@ResponseBody
	public List<EmployeeEntity> myfindAll() {
		
		List<EmployeeEntity> myfindAll = service.myfindAll();
		
		return myfindAll;
	}
	
	//http://localhost:8090/base-mapper/employee/myfindpage.do
	@RequestMapping("/myfindpage")
	@ResponseBody
	public List<EmployeeEntity> myfindpage() {
		
		List<EmployeeEntity> myfindAll = service.myfindpage();
		
		return myfindAll;
	}

}
